/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package metadatabrowser;

import at.fhj.itm.metadata.Column;
import at.fhj.itm.metadata.impl.postgres.PostgresColumn;
import at.fhj.util.Pair;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.Viewer;

/**
 *
 * @author Seuchter
 */
public class ColumnContentProvider implements IStructuredContentProvider {

    @Override
    public Object[] getElements(Object o)
    {

        if(!(o instanceof Column))
        {
            return null;
        }

        Column col = (Column) o;

        
        List<Pair<String,String>> properties = new ArrayList<Pair<String, String>>();

        properties.add(new Pair<String, String>("Name", col.getName()));



        if(col instanceof PostgresColumn)
        {
            PostgresColumn pgCol = (PostgresColumn) col;
            properties.add(new Pair<String, String>("Position", String.valueOf(pgCol.getColumnIndex())));
        }

        properties.add(new Pair<String, String>("Not null", String.valueOf(col.isNotNull())));
        properties.add(new Pair<String, String>("Type", col.getColumnType().getName() + col.getColumnType().getTypePostfix()));

        if(col.getDefaultValue() != null){
            properties.add(new Pair<String, String>("Default",col.getDefaultValue()));
        }

        return properties.toArray();

    }



    @Override
    public void dispose()
    {

    }

    @Override
    public void inputChanged(Viewer viewer, Object o, Object o1)
    {

    }

}
